﻿{% extends "base.html" %}

{% block title %}[订单号：{{token}}]订购{% endblock %}

{% block content %}
<a href="/ebp/" style="font-size:25px">[返回首页]</a> <a href="/logout/" style="font-size:25px">[注 销]</a>  
<form id="ebpform" name="ebpform" method="post" action="/submitebp/" >
<input type="hidden" id="counts" name="counts" value="{{counts}}" />
<input type="hidden" id="hideCountOfItem" value="0" />
<input type="hidden" id="hideSumOfItem"   value="0.0" />
<label>订单Token:</label> <input type="text" id="token" readonly name="token" value="{{token}}" style="width:100px" />
<input type="checkbox" id="refreshToken" name="refreshToken" value="yes" disabled /><label>刷新订单Token</label>
<table border="1" cellspacing="0" cellpadding="0" style="font-size:15px">
<tr>
	<th style="font-size:20px">&nbsp;</th>
	<th style="font-size:20px">名称</th>
	<th style="font-size:20px">单价</th>
	<th style="font-size:20px">数量</th>
	<!--<th>qty_ordered</th>-->
	<th>金额<!-- <span style="color:green">￥</span> --></th>
</tr>
{% for item in goodsLst %}
<tr>
	<td align="right"> {{item.sn}}</td> 
    <td><input type="text" name="item_name_{{ item.sn }}" id="item_name_{{ item.sn }}" value="{{ item.name }}" style="width:140px;font-size:20px" /> </td>
	<td><input type="text" name="item_price_{{ item.sn }}" id="item_price_{{ item.sn }}" style="width:40px;font-size:15px" value="{{item.price}}" readonly /></td>
	<td><select name="item_qty_{{item.sn}}" id="item_qty_{{item.sn}}" style="width:70px;font-size:20px;color:#8A2BE2">
		<script type="text/javascript">			
			$("#item_qty_{{item.sn}}").empty();
			$("#item_qty_{{item.sn}}").append("<option value =0 selected>0</option>");
			for(var i = 1 ; i <= {{item.qty_assigned}}; i++) {				
				if({{ item.qty_ordered }} == i)					
					$("#item_qty_{{item.sn}}").append("<option value = "+i+" selected>"+i+"</option>");				
				else
					$("#item_qty_{{item.sn}}").append("<option value = "+i+">"+i+"</option>");				
			}	
			
			if($("#item_qty_{{item.sn}}").val() != 0) {
			//	alert($("#item_qty_{{item.sn}}").val());
				$("#item_qty_{{item.sn}}").parents("tr").css("background-color","#9BCD9B");			
			}
			
			$("#item_qty_{{item.sn}}").change(function() {
				$("#item_sum_{{item.sn}}").attr("value",($("#item_price_{{ item.sn }}").val() * $("#item_qty_{{item.sn}}").val()));
				//$("#item_sum_{{item.sn}}").val(""+($("#item_price_{{ item.sn }}").val() * $("#item_qty_{{item.sn}}").val()));
				$("#countOfItem").attr("value",0)
				$("#sumOfItem").attr("value",0.0)					
				for(var i = 1; i <= $("#counts").val(); i++) {
					$("#countOfItem").attr("value",parseInt($("#countOfItem").val()) + parseInt($("#item_qty_" + i).val()));
					$("#sumOfItem").attr("value",parseFloat($("#sumOfItem").val()) + parseFloat($("#item_sum_" + i).val()));
				}
				// change color for selected <tr>	
        	//	$(this).parents("tr").css("font-style","italic");
        	//	$(this).parents("tr").css("color","red");
        		$(this).parents("tr").css("background-color","#EEAD0E");				
			//	$("#hideCountOfItem").attr("value",parseInt($("#countOfItem").val()));
			//	$("#hideSumOfItem").attr("value",parseFloat($("#sumOfItem").val()));
			});
		</script>
		</select>
	</td>
	<!--<td>{{item.qty_ordered }}</td>-->
	<td><input type="text" readonly name="item_sum_{{item.sn}}" id="item_sum_{{item.sn}}" value="{{item.sum_ordered}}" style="width:40px;font-size:15px;color:red"/></td>
</tr>
<script type="text/javascript">
$("#countOfItem").attr("value",parseInt($("#countOfItem").val()) + parseInt($("#item_qty_{{item.sn}}").val()));
$("#hideCountOfItem").attr("value",parseInt($("#hideCountOfItem").val()) + parseInt($("#item_qty_{{item.sn}}").val()));
$("#hideSumOfItem").attr("value",parseFloat($("#hideSumOfItem").val()) + parseFloat($("#item_sum_{{item.sn}}").val()));
</script>
{% endfor %}
</table>
<script type="text/javascript">
/**
	var counts = $("#counts").val()
	var countOfItem = 0;
	var sumOfItem = 0;
	for(var i = 1; i <= counts; i++) {
		countOfItem +=($("#item_qty_"+i).val());
		sumOfItem += ($("#item_sum_"+i).val());
	}
	$("#countOfItem").attr("value",countOfItem);
	$("#sumOfItem").attr("value",sumOfItem);
	alert('complete');
**/	
</script>
<br />
<div style="font-size:20px">
<label>数量:<input type="text" readonly id="countOfItem" name="countOfItem" value="0" style="width:70px;font-size:20px;color:red"/>条
<lable>金额:<input type="text" readonly id="sumOfItem" name="sumOfItem" value="0"  style="width:80px;font-size:20px;color:red"/>元
</div>
<script type="text/javascript">
	$("#countOfItem").attr("value",0);
	$("#sumOfItem").attr("value",0.0);
	$("#countOfItem").attr("value",$("#hideCountOfItem").val());
	$("#sumOfItem").attr("value",$("#hideSumOfItem").val());
	$("#hideCountOfItem").attr("value",0);
	$("#hideSumOfItem").attr("value",0.0);

</script>
<br />
<input type="submit" value="保存订单并提交" style="font-size:25px" /> <input type="button" value=" 注 销 " onclick="logout()" style="font-size:25px;" />
</form>


<script type="text/javascript">
	function logout() {
		window.location.href = "/logout/"
	}
</script>
{% endblock %}
